/**
 * Tag.java
 *
 *
 * $LastChangedBy: allen $
 * $LastChangedDate: 2007-11-27 11:57:18 +0800 $
 * $Revision: 1268 $
 */
package com.myspace.domain;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

@Entity(name = "Tag")
public class Tag extends DomainObject {

	private static final long serialVersionUID = 20071116L;

	private Long id;

	private String name;

	private List<Picture> pictures;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "seq_tag")
	@SequenceGenerator(name = "seq_tag", sequenceName = "SEQ_TAG")
	public Long getId() {
		return id;
	}

	void setId(Long id) {
		this.id = id;
	}

	@Column(updatable = false)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@ManyToMany(fetch = FetchType.LAZY, mappedBy = "tags")
	public List<Picture> getPictures() {
		return pictures;
	}

	public void setPictures(List<Picture> pictures) {
		this.pictures = pictures;
	}

	@Override
	@Transient
	public boolean isPersistence() {
		return id != null;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!(obj instanceof Tag))
			return false;
		return new EqualsBuilder().append(this.getId(), ((Tag) obj).getId())
				.append(this.getName(), ((Tag) obj).getName()).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(this.getId())
				.append(this.getName()).toHashCode();
	}

}
